Repository navigation
fix(watch): account a delivering attached close as success - #8
Merged
Merged
Conversation
Under wake-heavy load an arm attached to another arm's watcher reported "watcher: FAILED - cycle ended without an actionable reason" and exited 1 every time that watcher closed after successfully delivering its wake. The attached arm can only observe the lock disappearing: the reason line goes to the stdout of the arm that owns the watcher as a child. The watcher now publishes an identity-bound receipt as it delivers a wake, and the arm accounts a close as successful only when the receipt names the exact attached pid, the lock identity captured at attach, and a delivery no older than that cycle. It then repeats the delivered reason so the adapter notifies exactly as it does for an owned actionable close. Any other outcome, including a stale, foreign, or recycled-pid receipt, still reports the typed failure and exits nonzero. The same incident window showed the Claude turn-end guard blocking turns whose auto-arm was working normally. The auto-arm resolves session-lock ancestry before it may claim a home, and that walk cost 2.5-3.3s on a loaded machine against the guard's 800ms cooperative window, because it forked ps, basename, and grep on every hop. Ancestry now reads /proc with no forks at all and falls back to a single ps snapshot elsewhere: 18-40ms on the same machine, with both paths resolving the identical harness pid.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
Under wake-heavy load, an arm attached to another arm's watcher printed
watcher: FAILED - cycle ended without an actionable reasonand exited 1 every timethat watcher closed after successfully delivering its wake.
Confirmed from the main home's own lifecycle ledger (
state/.watch-cycle-exits.log),where the pattern repeats: a
startedarm recordsreason=actionable-signal exit_code=0,and the arm that attached ~4s later records
reason=attached-cycle-ended successor=noneabout 12 seconds afterward (the successor confirmation window):
Root cause: an attached arm can only observe the singleton lock disappearing. The wake
reason goes to the stdout of the arm that owns that watcher as a child, so a successful
delivering close was indistinguishable from a dead cycle.
That false alarm was also self-sustaining: the Claude auto-arm translates
watcher: FAILEDinto a banner telling the model supervision is down and to re-arm by hand, which is what put
two competing arms in one home in the first place.
Compounding symptom, same window
The turn-end guard blocked 4 turns with "The Stop-owned auto-arm did not claim this home either"
while wakes were flowing normally. Measured on this machine (2026-07-27, loaded):
The auto-arm must resolve session-lock ancestry before it may claim a home, and
bin/fm-turnend-guard.sh --claudeallows a stop only if that claim lands insideFM_CLAUDE_AUTOARM_SYNC_WAIT_MS(800ms). The walk forkedps,basename, andgreponevery hop (up to ~40 forks), so under load the guard blocked turns whose auto-arm was
working normally. The two symptoms share the incident, not the code path; both are fixed.
The fix
bin/fm-push-transition-lib.sh:wake()publishes an identity-bound receipt(
state/.watch-cycle-delivery: watcher pid,fm_pid_identity, timestamp, reason) as itdelivers.
bin/fm-watch-arm.sh: when an attached chain ends, a receipt matching the exactattached pid, the lock identity captured at attach, and a delivery no older than that
cycle closes the arm successfully with
watcher: closed pid=<N> (wake delivered by its owning arm)plus the delivered reason, so every adapter notifies exactly as it does foran owned actionable close. Anything else - no receipt, stale, foreign, or recycled pid -
still emits the typed failure and exits nonzero. Successor attach is still tried first, so
the Pi/OpenCode "start the successor before delivering" ordering is unchanged.
bin/fm-session-lock-lib.sh: ancestry resolution reads/procwith no forks and fallsback to a single
pssnapshot on hosts without it. 18-40ms after the change, with the/procandpspaths resolving the identical harness pid.Cross-adapter check: the arm-layer change is additive to a path that previously only ever
failed, and the new line is classified by the same
^(signal:|stale:|check:|heartbeat)grep every adapter already uses (claude Stop-owned, grok background-notify, codex
checkpoint, opencode/pi extensions). No adapter file changed.
docs/watcher-continuity.mdupdated because the arm-layer cycle contract itself gained aterminal outcome;
docs/turnend-guard.mdgained one line naming the claim-latencyconstraint its 800ms window depends on.
Local verification
GitHub Actions is billing-disabled fleet-wide, so local runs are the gate.
New regression coverage:
tests/fm-watcher-lock.test.sh- a real seed watcher delivers a real wake while a secondarm is attached: the attached arm exits 0, reports the delivering close, repeats the
reason, and logs
reason=attached-cycle-delivered.tests/fm-watcher-lock.test.sh- a receipt with the correct pid and identity but an oldtimestamp still yields
watcher: FAILEDand a nonzero exit, so real failure detection isnot weakened. The pre-existing kill-the-seed cases cover the no-receipt failure.
tests/fm-claude-stop-autoarm.test.sh- a delivering close translates to an ordinary wakerewake (exit 2,
outcome=rewake), never the supervision-down alarm.tests/fm-claude-stop-autoarm.test.sh- ancestry resolves withpsstubbed to failoutright (proving the fork-free
/procpath) and still resolves the same pid through thepsfallback with/procunavailable. Verified to fail against the old implementation.Pre-existing failures, unrelated and reproduced identically on
origin/main(checked out
bin tests docsfromorigin/mainand re-ran):tests/fm-watch-triage.test.sh- "dead-agent declared pause flooded stale wakes acrosssix unchanged polls" (
awk: cannot open .../state/.wake-queue).tests/fm-pi-watch-extension.test.sh- "OpenCode watch plugin must arm only when thissession owns the fleet lock: expected exit 0, got 1".